﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading;

namespace ServerMoniter
{
    public partial class MoniterService : ServiceBase
    {
        private Thread thread = null;

        //private static PerformanceCounter pcCpuLoad = new PerformanceCounter();   //CPU计数器 

        private ServerMoniterCls moniter = new ServerMoniterCls();

        public MoniterService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            eventLog.WriteEntry("系统监测服务启动 " + DateTime.Now.ToString());

            thread = new Thread(new ThreadStart(moniter.RunThreadService));

            thread.Start();
        }

        protected override void OnStop()
        {
            moniter.ExitThreadService();

            thread.Join(1000);

            Thread.Sleep(20);

            thread.Abort();

            eventLog.WriteEntry("停止系统监测服务");

        }
    }
}
